package com.hrm.websocket;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.json.simple.JSONObject;

public class OfflineMessagesThread {
	private WebSocketSession session;
	
	public OfflineMessagesThread(WebSocketSession session){
		this.session=session;
	}
	
	public void run(){
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		List<Object> mesList=session.getOffLineMessage();
		if(mesList==null||mesList.size()==0){
			return;
		}
		
		synchronized (mesList) {
			for(Object o:mesList){
				JSONObject jo=(JSONObject)o;
				session.send(jo.toJSONString().getBytes());
			}
		}
	}
}
